package com.ruin.tech.ahri.service.impl;

import com.ruin.tech.ahri.dao.NoticeMapper;
import com.ruin.tech.ahri.dao.VideoMapper;
import com.ruin.tech.ahri.model.dto.Notice;
import com.ruin.tech.ahri.model.dto.NoticeExample;
import com.ruin.tech.ahri.model.dto.Video;
import com.ruin.tech.ahri.model.dto.VideoExample;
import com.ruin.tech.ahri.model.vo.VideoAndNoticeVO;
import com.ruin.tech.ahri.service.IInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program ahri
 * @description: 通用信息获取服务
 * @author: ruin
 * @create: 2019/11/28 16:03
 */

@Service
public class InfoServiceImpl implements IInfoService {

    @Autowired
    VideoMapper videoMapper;

    @Autowired
    NoticeMapper noticeMapper;

    @Override
    public VideoAndNoticeVO getVideoAndNotice() {
        VideoAndNoticeVO videoAndNoticeVO = new VideoAndNoticeVO();
        VideoExample videoExample = new VideoExample();
        videoExample.setOrderByClause("create_time desc");
        List<Video> videos = videoMapper.selectByExample(videoExample);
        if(videos.size()>0){
            videoAndNoticeVO.setVideo(videos.get(0));
        }else{
            videoAndNoticeVO.setVideo(null);
        }

        NoticeExample noticeExample = new NoticeExample();
        noticeExample.setOrderByClause("create_time desc");
        List<Notice> notices = noticeMapper.selectByExample(noticeExample);
        if(notices.size()>0){
            videoAndNoticeVO.setNotice(notices.get(0));
        }else{
            videoAndNoticeVO.setNotice(null);
        }

        return videoAndNoticeVO;
    }
}
